package cn.news.controller;

import cn.news.pojo.News;
import cn.news.sevice.NewsService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class NewsController {
    @Reference
    private NewsService newsService;
    //查询新闻信息
    @RequestMapping("/queue.do")
    public String getNewsList(Integer categoryId,String title){
        return JSON.toJSONString(newsService.getnewsList(categoryId,title));
    }

    //根据新闻id查询新闻信息
    @RequestMapping("/news.json")
    public String getNews(Integer newsId){
        System.out.println(newsId);
        News news = newsService.getNewsBynewsId(newsId);
        System.out.println(news.getTitle()+"--"+news.getAuthor()+"---"+news.getSummary());
        return JSON.toJSONString(newsService.getNewsBynewsId(newsId));
    }
    //更新新闻信息
    @RequestMapping("/updateNews.do")
    public String updateNews(News news){
        Date date = new Date();
        news.setUpdateDate(date);
        if(newsService.updateNewsByNewsId(news)>0){
            return "更新成功！";
        }
        return "更新失败！";
    }
}
